package com.ymttest.business.service;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.client.ClientProtocolException;

import com.ymatou.i.accounting.api.parameter.AccountingBean;
import com.ymatou.i.accounting.api.parameter.AccountingItemBean;
import com.ymatou.i.accounting.api.parameter.CreateAccountBean;
import com.ymatou.i.accounting.api.parameter.GetAccountByUserIdBean;
import com.ymatou.i.accounting.api.parameter.SetAccountLockStatusBean;
import com.ymatou.i.accounting.api.service.AccountingCall;
import com.ymatou.i.accounting.api.service.CreateAccountCall;
import com.ymatou.i.accounting.api.service.GetAccountByUserIdCall;
import com.ymatou.i.accounting.api.service.SetAccountLockStatusCall;
import com.ymatou.iapi.exp.parameter.AddUserExpBean;
import com.ymatou.iapi.exp.service.AddUserExpCall;
import com.ymt.core.tool.Logger;
import com.ymttest.common.enums.AccountOperateTypeEnum;
import com.ymttest.database.model.FestivalRateConfig;
import com.ymttest.database.model.UserExp;
import com.ymttest.database.model.UserExpDetail;
import com.ymttest.database.sqlwapper.AccountDefaultWapper;
import com.ymttest.database.sqlwapper.ExpWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

public class ExpCallService {

	/**设置节日倍率
	 * @param rate 倍率
	 * @param enable 是否启用
	 */
	public static void resetFestivalRateConfig(double rate,boolean enable){
		Logger.comment("设置节日倍率:"+rate+",是否启用:"+enable);
		ExpWapper ew = new ExpWapper();
		ew.deleteFestivalRateConfig(YMTDateUtil.getSysTime("yyyy-MM-dd"));
		FestivalRateConfig frc=new FestivalRateConfig();
		frc.setCreateTime(YMTDateUtil.getDate());
		frc.setDate(YMTDateUtil.getSysTime("yyyy-MM-dd"));
		frc.setRate(rate);
		frc.setEnable(enable);
		frc.setLastUpdateTime(YMTDateUtil.getDate());
		frc.setRemark("autoTest");
		ew.insertFestivalRateConfig(frc);
	}
    /**
     * 使用购买商品初始化经验，最小20
     * @param uid
     * @param exp
     */
    public static AddUserExpBean resetExp(int uid,int exp1) {
        try {
        	Logger.comment(uid+":初始化经验值:"+exp1);
        	ExpWapper ew = new ExpWapper();
        	ew.deleteuserexp(uid);
			ew.deleteuserexpdetail(uid, null, null, null);
        	if(exp1<20){
        		if(exp1==0){
        			return null;
        		}
        		Logger.comment("exp过小,初始化失败");
        		return null;
        	}
        	AddUserExpBean adduserexpBean=new AddUserExpBean();
        	AddUserExpCall adduserexpCall=new AddUserExpCall();
			
			adduserexpBean.setUserId(uid);
			adduserexpBean.setBizCode("100102");
			adduserexpBean.setBizNo(YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"));
			Map parameters=new HashMap<>();
			parameters.put("isSubmit", true);
			parameters.put("totalPrice",exp1);
			adduserexpBean.setParameters(parameters);
			adduserexpCall.setData(false,adduserexpBean);
			adduserexpCall.callService();
			return adduserexpBean;
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
		return null;
    }
    /**
     * 使用购买商品增加exp，最小20
     * @param uid
     * @param exp1
     */
    public static AddUserExpBean addExp(int uid,int exp1) {
    	Logger.comment(uid+":添加经验值:"+exp1);
        try {
        	ExpWapper ew = new ExpWapper();
        	AddUserExpBean adduserexpBean=new AddUserExpBean();
        	AddUserExpCall adduserexpCall=new AddUserExpCall();
			adduserexpBean.setUserId(uid);
			adduserexpBean.setBizCode("100102");
			adduserexpBean.setBizNo(YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"));
			Map parameters=new HashMap<>();
			parameters.put("isSubmit", true);
			parameters.put("totalPrice",exp1);
			adduserexpBean.setParameters(parameters);
			adduserexpCall.setData(false,adduserexpBean);
			
			adduserexpCall.callService();
			return adduserexpBean;

        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
		return null;
    }
    /**
     * 使用不同类型添加经验值
     * @param uid
     * @param exp1
     * @param type 100101 打开APP获得经验值 100102	购买商品获得经验值 100104	主动评价订单获得经验值 1002021	订单取消扣除经验值（全部） 1002022	订单取消扣除经验值（部分）
     * @return
     * @throws InterruptedException 
     */
    public static AddUserExpBean addExp(int uid,int exp1,int type) throws InterruptedException {
        try {
        	Logger.comment(uid+":增加经验值:"+exp1);
        	ExpWapper ew = new ExpWapper();
        	AddUserExpBean adduserexpBean=new AddUserExpBean();
        	AddUserExpCall adduserexpCall=new AddUserExpCall();
			if(type==100101){
				adduserexpBean.setUserId(uid);
				adduserexpBean.setBizCode("100101");
				adduserexpBean.setBizNo(YMTDateUtil.getSysTime("yyyyMMdd"));
				adduserexpCall.setData(false,adduserexpBean);
				adduserexpCall.callService();
				Thread.sleep(2000);
			}else if(type==100102){
				adduserexpBean.setUserId(uid);
				adduserexpBean.setBizCode("100102");
				adduserexpBean.setBizNo(YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"));
				Map parameters=new HashMap<>();
				parameters.put("isSubmit", true);
				parameters.put("totalPrice",exp1);
				adduserexpBean.setParameters(parameters);
				adduserexpCall.setData(false,adduserexpBean);
				adduserexpCall.callService();
			}
			else if(type==100104){
				adduserexpBean.setUserId(uid);
				adduserexpBean.setBizCode("100104");
				adduserexpBean.setBizNo(YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"));
				Map parameters=new HashMap<>();
				parameters.put("isSubmit", true);
				parameters.put("isContainImageText", true);
				parameters.put("totalPrice",exp1*5);
				adduserexpBean.setParameters(parameters);
				adduserexpCall.setData(false,adduserexpBean);
				adduserexpCall.callService();
			}
			else if(type==1002021){
				AddUserExpBean adduserexpBean1 = ExpCallService.addExp(uid, exp1);
				Thread.sleep(1000);
				adduserexpBean.setUserId(adduserexpBean1.getUserId());
				adduserexpBean.setBizCode("100202");
				adduserexpBean.setBizNo(adduserexpBean1.getBizNo());
				adduserexpCall.setData(false,adduserexpBean);
				adduserexpCall.callService();
			}
			else if(type==1002022){
				//2次部分取消
				AddUserExpBean adduserexpBean1 = ExpCallService.addExp(uid, exp1*2+10);
				Thread.sleep(1000);
				adduserexpBean.setUserId(adduserexpBean1.getUserId());
				adduserexpBean.setBizCode("100202");
				adduserexpBean.setBizNo(adduserexpBean1.getBizNo());
				Map parameters=new HashMap<>();
				parameters.put("specId", YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"));
				parameters.put("price",exp1);
				adduserexpBean.setParameters(parameters);
				adduserexpCall.setData(false,adduserexpBean);
				adduserexpCall.callService();
				parameters.put("specId", YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"));
				adduserexpCall.callService();
			}
			return adduserexpBean;
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
		return null;
    }
    public static void main(String[] args) throws Exception {
    }
}
